from .models import DepartmentPost, AssociationPost

# 遇到需要回传多个数据时默认大小
DEFAULT_SLICE_SIZE = 8


def get_all_recent_posts_of_departments():
    """获取所有部门的近期文章"""
    return DepartmentPost.objects.filter(
        status=DepartmentPost.STATUS_NORMAL,
    ).order_by('-created_time')


def get_all_popular_posts_of_departments():
    """获取所有部门的热门文章"""
    return DepartmentPost.objects.filter(
        status=DepartmentPost.STATUS_NORMAL,
    ).order_by('-nov')


def get_specified_number_of_recent_posts_of_departments(number=DEFAULT_SLICE_SIZE):
    """获取所有部门指定数量的近期文章"""
    return DepartmentPost.objects.filter(
        status=DepartmentPost.STATUS_NORMAL,
    ).order_by('-created_time')[:number]


def get_specified_number_of_popular_posts_of_departments(number=DEFAULT_SLICE_SIZE):
    """获取所有部门指定数量的热门文章"""
    return DepartmentPost.objects.filter(
        status=DepartmentPost.STATUS_NORMAL,
    ).order_by('-nov')[:number]


def get_all_recent_posts_of_specified_department(department_id):
    """获取指定部门的近期文章"""
    return DepartmentPost.objects.filter(
        status=DepartmentPost.STATUS_NORMAL,
        department_id=department_id
    ).order_by('-created_time')


def get_all_popular_posts_of_specified_department(department_id):
    """获取指定部门所有的热门文章"""
    return DepartmentPost.objects.filter(
        status=DepartmentPost.STATUS_NORMAL,
        department_id=department_id
    ).order_by('-nov')


def get_specified_number_of_recent_posts_of_specified_department(department_id, number=DEFAULT_SLICE_SIZE):
    """获取指定部门的指定数量的近期文章"""
    return DepartmentPost.objects.filter(
        status=DepartmentPost.STATUS_NORMAL,
        department_id=department_id
    ).order_by('-created_time')[:number]


def get_specified_number_of_popular_posts_of_specified_department(department_id, number=DEFAULT_SLICE_SIZE):
    """获取指定部门的指定数量的热门文章"""
    return DepartmentPost.objects.filter(
        status=DepartmentPost.STATUS_NORMAL,
        department_id=department_id
    ).order_by('-nov')[:number]


def get_all_recent_posts_of_associations():
    """获取所有社团的近期文章"""
    return AssociationPost.objects.filter(
        status=AssociationPost.STATUS_NORMAL
    ).order_by('-created_time')


def get_all_popular_posts_of_associations():
    """获取所有社团的热门文章"""
    return AssociationPost.objects.filter(
        status=AssociationPost.STATUS_NORMAL
    ).order_by('-nov')


def get_specified_number_of_recent_posts_of_associations(number=DEFAULT_SLICE_SIZE):
    """获取所有社团指定数量的近期文章"""
    return AssociationPost.objects.filter(
        status=AssociationPost.STATUS_NORMAL
    ).order_by('-created_time')[:number]


def get_specified_number_of_popular_posts_of_associations(number=DEFAULT_SLICE_SIZE):
    """获取所有社团指定数量的热门文章"""
    return AssociationPost.objects.filter(
        status=AssociationPost.STATUS_NORMAL
    ).order_by('-nov')[:number]


def get_all_recent_posts_of_specified_association(association_id):
    """获取特定社团的近期文章"""
    return AssociationPost.objects.filter(
        status=AssociationPost.STATUS_NORMAL,
        id=association_id
    ).order_by('-created_time')


def get_all_popular_posts_of_specified_association(association_id):
    """获取特定社团的热门文章"""
    return AssociationPost.objects.filter(
        status=AssociationPost.STATUS_NORMAL,
        id=association_id
    ).order_by('-nov')


def get_specified_number_of_recent_posts_of_specified_association(association_id, number=DEFAULT_SLICE_SIZE):
    """获取指定社团的指定数量的近期文章"""
    return AssociationPost.objects.filter(
        status=AssociationPost.STATUS_NORMAL,
        id=association_id
    ).order_by('-created_time')[:number]


def get_specified_number_of_popular_posts_of_specified_association(association_id, number=DEFAULT_SLICE_SIZE):
    """获取指定社团的指定数量的热门文章"""
    return AssociationPost.objects.filter(
        status=AssociationPost.STATUS_NORMAL,
        id=association_id
    ).order_by('-nov')[:number]

# 以后如果有类似于用户推荐、优秀评论推荐等等功能也可以添加到这个模块中
